package C;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class C18 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i=0;i<100;i++) {
            list.add(i);
        }
        while(sc.hasNextLine()) {
            String line = sc.nextLine();
            if (line.isEmpty()) {
                break;
            }
            int[] pAndSize= Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt).toArray();
            int p = pAndSize[0],size = pAndSize[1];
            for (int i=p;i<p+size;i++) {
                list.remove(Integer.valueOf(i));
            }
        }
        System.out.println(list);
        System.out.println(getResult(n,list));


    }

    public static int getResult(int n,ArrayList<Integer> list) {
        int bestSize = Integer.MAX_VALUE;
        int p = 0;
        for (int i=0;i< list.size();i++) {
            //越界访问，剩余空间不足
            if (i+n-1>=list.size()) return -1;
            //剩余空间充足且当前连续空间至少有n个
            if (list.get(i)+n-1 == list.get(i+n-1)){
                int maybe = list.get(i);
                System.out.println("i="+i);
                while((i+1)<list.size() && list.get(i)+1 == list.get(i+1)) {
                    i++;
                }
                int currentSize = list.get(i)-maybe+1;
                if (currentSize < bestSize) {
                    bestSize = currentSize;
                    p = maybe;
                }
            }
        }
        if (bestSize!=Integer.MAX_VALUE) return p;
        return -1;
    }
}
